package com.yanzhengwu.boot;

import com.yanzhengwu.boot.core.common.annotation.DynamicDataSourceEnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.springframework.boot.WebApplicationType.SERVLET;

/**
 * Spring Boot 项目启动类
 * TODO 启动类使用 @DynamicDataSourceEnable 注解自动装配数据源
 */
@DynamicDataSourceEnable
@SpringBootApplication
public class Application {

    private static Logger log = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) throws UnknownHostException {

        ConfigurableApplicationContext application = new SpringApplicationBuilder(Application.class).web(SERVLET).run(args);
        Environment env = application.getEnvironment();
        log.info("\n----------------------------------------------------------\n\t" +
                        "项目运行成-功! 访问连接:\n\t" +
                        "后台地址: \t\thttp://{}:{}\n" +
                        "druid地址: \t\thttp://localhost:8080/druid/login.html\n" +
                        "----------------------------------------------------------",
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"));
    }



}
